package virtualadvisor;

import java.awt.BorderLayout;
import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JComboBox;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.LinkedList;
import java.util.List;
import javax.swing.DefaultComboBoxModel;

public class PlanWizard extends JDialog {

	private static final long serialVersionUID = 1L;
	private final JPanel contentPanel = new JPanel();
	private JComboBox comboBox_SelectMinor;
	private Profile mainProfile;
	static private final boolean DEBUG = false; 

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		try {
			Profile p = new Profile();
			PlanWizard dialog = new PlanWizard(p);
			dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
			dialog.setVisible(true);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Create the Plan Wizard Dialog.
	 */
	public PlanWizard(Profile profile) {
		setTitle("Virtual Advisor - Plan Wizard");
		setResizable(false);
		mainProfile = profile;
		setBounds(100, 100, 450, 185);
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.CENTER);
		contentPanel.setLayout(null);

		JLabel label_PlanWizard = new JLabel("Plan Wizard");
		label_PlanWizard.setFont(new Font("Tahoma", Font.BOLD, 18));
		label_PlanWizard.setBounds(6, 6, 180, 29);
		contentPanel.add(label_PlanWizard);

		JLabel label_SelectMajor = new JLabel("Select Major");
		label_SelectMajor.setFont(new Font("Tahoma", Font.BOLD, 12));
		label_SelectMajor.setBounds(6, 47, 83, 14);
		contentPanel.add(label_SelectMajor);

		JLabel label_SelectMinor = new JLabel("Select Minor");
		label_SelectMinor.setFont(new Font("Tahoma", Font.BOLD, 12));
		label_SelectMinor.setBounds(6, 83, 83, 14);
		contentPanel.add(label_SelectMinor);

		final JComboBox comboBox_SelectMajor = new JComboBox(new String[]{});
		comboBox_SelectMajor.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if(comboBox_SelectMajor.getSelectedItem().equals("Computer Science Major (CMSC)")){
					comboBox_SelectMinor.setVisible(false);
				} else {
					comboBox_SelectMinor.setVisible(true);
				}
			}
		});
		comboBox_SelectMajor.setModel(new DefaultComboBoxModel(new String[] {"", "Computer Science Major (CMSC)", "Information Systems Major (IS)"}));
		comboBox_SelectMajor.setBounds(101, 41, 257, 22);
		contentPanel.add(comboBox_SelectMajor);

		comboBox_SelectMinor = new JComboBox(new String[]{"","Computer Science Minor (CMSC)"});
		comboBox_SelectMinor.setBounds(101, 77, 258, 22);
		contentPanel.add(comboBox_SelectMinor);

		JLabel label_Optional = new JLabel("(Optional)");
		label_Optional.setFont(new Font("Tahoma", Font.BOLD, 11));
		label_Optional.setBounds(371, 82, 69, 14);
		contentPanel.add(label_Optional);

		JPanel buttonPane = new JPanel();
		buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
		getContentPane().add(buttonPane, BorderLayout.SOUTH);
			
		JButton button_CreatePlan = new JButton("Create Plan");
		button_CreatePlan.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				//System.out.println("Name: " + name);
				String majorSelected = (String) comboBox_SelectMajor.getSelectedItem();
				if(majorSelected.equals("")){
					JOptionPane.showMessageDialog(contentPanel,
						"Please Enter A Major.",
						"Warning", JOptionPane.WARNING_MESSAGE);
				} else {
					String minorSelected = (String)comboBox_SelectMinor.getSelectedItem();
					if(DEBUG) {
						System.out.println(majorSelected);
						System.out.println(minorSelected);
					}
					
					//TODO Add name, majorSelected, minorSelected to Save Profile Information
					List<String> lMaj = new LinkedList<String>();
					lMaj.add(majorSelected);
					
					//DegreeProgress dp = mainProfile.getProgress();
					
				}
			}
		});
		button_CreatePlan.setActionCommand("Create Plan");
		buttonPane.add(button_CreatePlan);
		getRootPane().setDefaultButton(button_CreatePlan);

		JButton button_Cancel = new JButton("Cancel");
		button_Cancel.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				setVisible(false);
				ProfileSelector dialog = new ProfileSelector(mainProfile);
				
				dialog.setVisible(true);
				dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
			}
		});
		button_Cancel.setActionCommand("Cancel");
		buttonPane.add(button_Cancel);
	}
}
